/// 返回UTC日期时间
#[inline(always)]
pub fn utc_time() -> DateTime
{
    unsafe {
        let mut t: libc::time_t = 0;
        libc::time(&mut t as *mut libc::time_t);
        let mut tt: libc::tm = std::mem::zeroed();
        libc::gmtime_r(&t as *const libc::time_t, &mut tt as *mut libc::tm);
        DateTime {
            year: tt.tm_year as u16,
            month: tt.tm_mon as u8,
            day: tt.tm_mday as u8,
            week: tt.tm_wday as u8,
            hour: tt.tm_hour as u8,
            minute: tt.tm_min as u8,
            second: tt.tm_sec as u8,
        }
    }
}

/// 返回本地日期时间
#[inline(always)]
pub fn local_time() -> DateTime
{
    unsafe {
        let mut t = 0i64;
        libc::time(&mut t as *mut i64);
        let mut tt: libc::tm = std::mem::zeroed();
        libc::localtime_r(&t as *const i64, &mut tt as *mut libc::tm);
        DateTime {
            year: tt.tm_year as u16,
            month: tt.tm_mon as u8,
            day: tt.tm_mday as u8,
            week: tt.tm_wday as u8,
            hour: tt.tm_hour as u8,
            minute: tt.tm_min as u8,
            second: tt.tm_sec as u8,
        }
    }
}

/// 获取系统启动以来经过的毫秒数
#[inline(always)]
pub fn tick_count() -> u64
{
    unsafe {
        let mut t = libc::timespec { tv_sec: 0, tv_nsec: 0 };
        libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut t as *mut libc::timespec);
        (t.tv_sec + (t.tv_nsec / 1000000)) as u64
    }
}
